package Contest.week93;

public class _868_BinaryGap {
    public int binaryGap(int N) {
        String bn = Integer.toBinaryString(N);
        int distance = 0;
        boolean enter = false;
        int temp = 0;
        for (int i = 0; i < bn.length(); i++) {
            if (bn.charAt(i) == '1') {
                if (!enter) {
                    enter = true;
                    temp = 0;
                } else {
                    temp++;
                    if (temp > distance) {
                        distance = temp;
                    }
                    temp = 0;
                }
            } else {
                temp++;
            }
        }
        return distance;
    }
}
